package com.hup.sidebar.framework.util;

import android.annotation.SuppressLint;
import android.content.Context;
import android.widget.Toast;

/**
 * bug: 快速点击时,toast不能马上显示最新内容(偶然),系统问题??
 *
 * @author hugan
 * @date 2022/4/5
 */
public class ToastUtil {

    private static Toast toastShort, toastLong;

    @SuppressLint("ShowToast")
    public static void init(Context context) {
        toastShort = Toast.makeText(context, "", Toast.LENGTH_SHORT);
        toastLong = Toast.makeText(context, "", Toast.LENGTH_LONG);
    }

    /**
     * Toast.LENGTH_SHORT
     */
    public static void short_(String msg) {
        /*
        - 5.1后, 先cancel 反而不显示toast?
        - ?后, 先cancel,再show也不会更新toast
        - 不同设备有差异
         */
        //toastShort.cancel();
        toastShort.setText(msg);
        toastShort.show();
    }

    /**
     * Toast.LENGTH_LONG
     */
    public static void long_(String msg) {
        //toastLong.cancel();
        toastLong.setText(msg);
        toastLong.show();
    }

}
